import { ActiveBaseIcon } from "../activity/icon/ActiveBaseIcon";
import { LayerManager } from "../../manager/LayerManager";
import { Global } from "../../../../com/gengine/global/Global";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GameController } from "../../mvc/GameController";
import { Cache } from "../../cache/Cache";
import { Language } from "../../../../extend/language/Language";
import { ClockManager } from "../../manager/ClockManager";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class FlameIconView
    
    export  class FlameIconView extends ActiveBaseIcon
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.initBase();
            this.createChildren();
            this.addEventListeners();
            this.hide();
            return;
        }

        /* internal  */initBase(): void
        {
            this.layer = LayerManager.rightTopUILayer;
            this.x = Global.stage.stageWidth - 335;
            this.y = 10;
            return;
        }

        /* internal  */createChildren(): void
        {
            this._btnIcon = ObjCreate.createGLoadedButton(ResFileConst.GuildFlameIcon, 0, 0, 50, 50, this);
            this._tfCountdown = ObjCreate.createTextField("", -4, 50, 54, 20, this, GlobalStyle.textFormat5);
            return;
        }

        /* internal  */addEventListeners(): void
        {
            this._btnIcon.addEventListener(flash.events.MouseEvent.CLICK, this.onClickFlameIcon);
            return;
        }

        /* internal  */onClickFlameIcon(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var onClose1: Function;
            var onClose2: Function;

            var loc1;
            onClose1 = null;
            onClose2 = null;
            e = arg1;
            onClose1 = (arg1: int): void
            {
                if (arg1 == Alert.OK) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildQuickBackFlame));
                }
                return;
            }
            onClose2 = (arg1: int): void
            {
                if (arg1 == Alert.OK) 
                {
                    GameController.guild.view.show();
                }
                return;
            }
            if (Cache.instance.guild.myGuildInfo) 
            {
                if (!Cache.instance.guild.isInSelfManorMap()) 
                {
                    Alert.show(Language.getString(41703), null, Alert.OK | Alert.CANCEL, null, onClose1);
                }
            }
            else 
            {
                Alert.show(Language.getString(41704), null, Alert.OK | Alert.CANCEL, null, onClose2);
            }
            return;
        }

        public startCountdown(arg1: Date): void
        {
            this._endDate = arg1;
            var loc1=new Date(this._endDate.time - ClockManager.instance.nowDate.time);
            var loc2=Math.ceil(loc1.time / 1000);
            if (this._secTimer) 
            {
                this._secTimer.reset();
                this._secTimer.repeatCount = loc2;
            }
            else 
            {
                this._secTimer = new SecTimer(1, loc2);
            }
            this._secTimer.start();
            this._secTimer.addListener(TimerType.ENTERFRAME, this.onTimeChange);
            return;
        }

        /* internal  */onTimeChange(arg1: SecTimer): void
        {
            var loc1=arg1.repeatCount;
            var loc2=loc1 / 3600;
            var loc3=loc1 % 3600 / 60;
            var loc4=loc1 % 60;
            var loc5=(loc2 < 10 ? "0" : "") + loc2;
            var loc6=(loc3 < 10 ? "0" : "") + loc3;
            var loc7=(loc4 < 10 ? "0" : "") + loc4;
            this._tfCountdown.text = loc5 + ":" + loc6 + ":" + loc7;
            return;
        }

        /* internal  */stopCountDown(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.stop();
            }
            return;
        }

        public static get instance(): FlameIconView
        {
            if (!FlameIconView._instance) 
            {
                FlameIconView._instance = new FlameIconView();
            }
            return FlameIconView._instance;
        }

        /* internal */ /* var */_btnIcon: GLoadedButton;

        /* internal */ /* var */_tfCountdown: Object /* flash.text.TextField */;

        /* internal */ /* var */_endDate: Date;

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ static /* var */_instance: FlameIconView;
    }
